import type { Supplier } from "@/pages/base/supplier/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
	//供应商编码
	supplierCode?: string;
	//供应商名称
	supplierName?: string;
	//是否启用
	status?: string;
	//当前页码
	page: number;
	//每页数量
	pageSize: number;
}

export interface PageListRes {
	//总记录数
	total: number;
	//数据列表
	records: Supplier[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
	apiClient.post({
		url: "/base/supplier/pageList",
		data,
	});

const treeList = (data: PageListReq): Promise<Supplier> => apiClient.post({ url: "/base/supplier/treeList", data });

const getInfo = (id: React.Key): Promise<Supplier> =>
	apiClient.get({
		url: `/base/supplier/${id}`,
	});

const add = (data: Supplier): Promise<Supplier> =>
	apiClient.post({
		url: "/base/supplier",
		data,
	});

const update = (data: Supplier): Promise<Supplier> =>
	apiClient.put({
		url: "/base/supplier",
		data,
	});

const remove = (ids: React.Key[]): Promise<void> =>
	apiClient.delete({
		url: "/base/supplier",
		params: {
			ids: ids.join(","),
		},
	});

export const supplierService = {
	pageList,
	treeList,
	getInfo,
	add,
	update,
	remove,
};

export default supplierService;
